package com.lei.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lei.eduservice.entity.EduCourse;
import com.lei.eduservice.entity.EduTeacher;
import com.lei.eduservice.service.EduCourseService;
import com.lei.eduservice.service.EduTeacherService;
import com.lei.utils.Result;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ
 * Author:熊磊
 */
@RestController
@RequestMapping("/edu/teacher/f")
//前台讲师接口
@Api("前台讲师接口")
public class FrontTeacherController {
    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;
    //分页查询
    @PostMapping("/getTeacherList/{current}/{limit}")
    public Result getTeacherList(@PathVariable("current") Long current,@PathVariable("limit") Long limit){
        Page<EduTeacher> teacherPage = new Page<>(current, limit);
        HashMap<String,Object> map=teacherService.getFrontTeacherList(teacherPage);
        return Result.ok().data(map);
    }

    //讲师详情
    @PostMapping("/getTeacher/{id}")
    public Result getTeacherList(@PathVariable("id") String id){
        //查询讲师
        EduTeacher teacher = teacherService.getById(id);
        //查询讲师的课程
        List<EduCourse> list = courseService.list(new QueryWrapper<EduCourse>().eq("teacher_id",teacher.getId()));
        return Result.ok().data("teacher",teacher).data("courseList",list);
    }

}
